﻿using Communergy.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Communergy.Common.Tests
{
    
    
    /// <summary>
    ///This is a test class for ConvertersTest and is intended
    ///to contain all ConvertersTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ConvertersTest
    {
		#region Methods (11) 

		// Public Methods (11) 

        [TestMethod()]
        public void Converters_1KWh_Extension_ShouldBe3600000Joules()
        {
            decimal kWh = 1.0M;
            int expectedJoules = 3600000;
            int actualJoules = kWh.KWhToJoules();
            Assert.AreEqual(expectedJoules, actualJoules);
        }

        [TestMethod()]
        public void Converters_1KWh_ShouldBe3600000Joules()
        {
            decimal kWh = 1.0M;
            int expectedJoules = 3600000;
            int actualJoules = EnergyConverters.KWhToJoules(kWh);
            Assert.AreEqual(expectedJoules, actualJoules);
        }

        /// <summary>
        ///A test for JoulesToKWh
        ///</summary>
        [TestMethod()]
        public void Converters_3600000Joules_ShouldBeOneKWh()
        {
            int joules = 3600000;
            Decimal expected = 1M;
            Decimal actual;
            actual = EnergyConverters.JoulesToKWh(joules);
            Assert.AreEqual(expected, actual);
            
        }

        [TestMethod()]
        public void Converters_3600000JoulesExtension_ShouldBeOneKWh()
        {
            int joules = 3600000;
            Decimal expected = 1M;
            Decimal actual;
            actual = joules.JoulesToKWh();
            Assert.AreEqual(expected, actual);

        }

        [TestMethod()]
        public void Converters_600Watts10Seconds_ShouldBe6000Joules()
        {
            int watts = 600;
            TimeSpan interval = new TimeSpan(0, 0, 10);
            int actualJoules = EnergyConverters.WattsIntervalToJoules(watts, interval);
            int expectedJoules = 6000;
            Assert.AreEqual(expectedJoules, actualJoules);
        }

        [TestMethod()]
        public void Converters_600Watts10SecondsExtension_ShouldBe6000Joules()
        {
            decimal watts = 600;
            TimeSpan interval = new TimeSpan(0, 0, 10);
            int actualJoules = watts.WattsIntervalToJoules(interval);
            int expectedJoules = 6000;
            Assert.AreEqual(expectedJoules, actualJoules);
        }

        [TestMethod()]
        public void Converters_972000JoulesExtension_ShouldBePoint27Kwh()
        {
            int joules = 972000;
            Decimal expected = 0.27M;
            Decimal actual;
            actual = joules.JoulesToKWh();
            Assert.AreEqual(expected, actual);

        }

        [TestMethod()]
        public void Converters_Feb2010TimeSpan_ShouldBe28Days()
        {
            DateTime feb2010 = new DateTime(2010, 02, 17);
            TimeSpan expectedTimeSpan = new TimeSpan(28, 0, 0, 0);
            TimeSpan actualTimespan = EnergyConverters.MonthTimeSpan(feb2010);
            Assert.AreEqual(expectedTimeSpan, actualTimespan);
        }

        [TestMethod()]
        public void Converters_Feb2012TimeSpan_ShouldBe29Days()
        {
            DateTime feb2012 = new DateTime(2012, 02, 17);
            TimeSpan expectedTimeSpan = new TimeSpan(29, 0, 0, 0);
            TimeSpan actualTimespan = EnergyConverters.MonthTimeSpan(feb2012);
            Assert.AreEqual(expectedTimeSpan, actualTimespan);
        }

        [TestMethod()]
        public void Converters_Feb2012TimeSpanExtension_ShouldBe29Days()
        {
            DateTime feb2012 = new DateTime(2012, 02, 17);
            TimeSpan expectedTimeSpan = new TimeSpan(29, 0, 0, 0);
            TimeSpan actualTimespan = feb2012.MonthTimeSpan();
            Assert.AreEqual(expectedTimeSpan, actualTimespan);
        }

        [TestMethod()]
        public void Converters_May2010TimeSpan_ShouldBe31Days()
        {
            DateTime may2010 = new DateTime(2010, 05, 17);
            TimeSpan expectedTimeSpan = new TimeSpan(31,0,0,0);
            TimeSpan actualTimespan = EnergyConverters.MonthTimeSpan(may2010);
            Assert.AreEqual(expectedTimeSpan, actualTimespan);
        }

        [TestMethod()]
        public void Converters_Point27KwhExtension_ShouldBe972000Joules()
        {
           
            Decimal kWh = 0.27M;
            var actualJoules = kWh.KWhToJoules();
            int expectedJoules = 972000;
            Assert.AreEqual(expectedJoules, actualJoules);

        }


        [TestMethod()]
        public void Converters_ConvertEnergyData600WattsForTenSecondsToInformation_ShouldCalculate6000Joules()
        {
            DateTime readingDateTime = new DateTime(2010, 5, 21, 0, 38, 0);
            TimeSpan interval = new TimeSpan(0, 0, 10);
           decimal watts = 600;

            EnergyData energyData = new EnergyData
            {
                ReadingDateTime = readingDateTime,
                Interval = interval,
                AverageWatts = watts
            };

            EnergyInformation energyInformation = EnergyConverters.EnergyInformationFromData(energyData);

            Assert.AreEqual(6000, energyInformation.Joules);
        }


        [TestMethod()]
        public void Converters_ConvertEnergyData600WattsForTenSecondsToInformationExtension_ShouldCalculate6000Joules()
        {
            DateTime readingDateTime = new DateTime(2010, 5, 21, 0, 38, 0);
            TimeSpan interval = new TimeSpan(0, 0, 10);
            decimal watts = 600;

            EnergyData energyData = new EnergyData
            {
                ReadingDateTime = readingDateTime,
                Interval = interval,
                AverageWatts = watts
            };

            EnergyInformation energyInformation = energyData.EnergyInformationFromData();

            Assert.AreEqual(6000, energyInformation.Joules);
        }


		#endregion Methods 
    }
}
